package com.du.fileload.framework.filter;

import com.du.fileload.framework.auth.JwtAuthenticationTokenFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class ResponseResultInterceptor implements HandlerInterceptor {
    /* 使用统一返回体的标识 */
    private static final String RESPONSE_RESULT_ANNOTATION = "RESPONSE-RESULT-ANNOTATION";

    private static final Logger log = LoggerFactory.getLogger(JwtAuthenticationTokenFilter.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        // 正在处理请求的方法bean
        log.debug("Request---- Request-Url: "+request.getRequestURI());
        log.debug("Request---- Content-Type: "+request.getContentType());
        log.debug("Request---- Query-String: "+request.getQueryString());
        String contentType=request.getContentType();
        if(contentType!=null&&contentType.equals("text/json;charset=utf-8")){
            //log.debug("Request---- RequestBody: "+request.get);
        }else{
        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
        // 正在处理请求的方法bean
        log.info("----------------");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
        log.debug("Response---- Request-Url: "+request.getRequestURI());
        log.debug("Response---- Content-Type: "+response.getContentType());
        log.debug("Response---- Complete!");
    }
}
